<!DOCTYPE html>
<html>
<head>
	<title>首页</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" href="../css/bootstrap.css">
	<link type="text/css" rel="stylesheet" href="../css/style.css">
	<script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../layer/layer.js"></script>
	<script type="text/javascript" src="../js/cart.js"></script>
	<script type="text/javascript" src="../js/auth.js"></script>
	<script type="text/javascript" src="../js/CookieShop.js"></script>
</head>
<body>
    <div class="header">
       <div class="container">
           <nav class="navbar navbar-default" role="navigation">
               <div class="navbar-header">
                   <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                       <span class="sr-only">Toggle navigation</span>
                       <span class="icon-bar"></span>
                       <span class="icon-bar"></span>
                       <span class="icon-bar"></span>
                   </button>
                   <h1 class="navbar-brand"><a href="./index"></a></h1>
               </div>
               <!--navbar-header-->
               <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                   <ul class="nav navbar-nav">
                       <li><a href="./index.html">首页</a></li>
                       <li class="dropdown">
                           <a href="#" class="dropdown-toggle" data-toggle="dropdown">商品分类<b class="caret"></b></a>
                           <ul class="dropdown-menu multi-column columns-2">
                               <li>
                                   <div class="row">
                                       <div class="col-sm-12">
                                           <h4>商品分类</h4>
                                           <ul class="multi-column-dropdown" id="goodsTypeMenu">
                                               <li><a class="list" href="./goods_list.html">全部系列</a></li>
                                           </ul>
                                       </div>
                                   </div>
                               </li>
                           </ul>
                       </li>
                       <li><a href="./goodsrecommend_list.html?recommendTypeId=2">热销</a></li>
                       <li><a href="./goodsrecommend_list.html?recommendTypeId=3">新品</a></li>


                   </ul>
                   <!--/.navbar-collapse-->
               </div>
               <!--//navbar-header-->
           </nav>
           <div class="header-info">
               <div class="header-right search-box">
                   <a href="javascript:;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
                   <div class="search">
                       <form class="navbar-form" action="">
                           <input type="text" class="form-control" name="keyword" id="keyword">
                           <button type="button" class="btn btn-default" aria-label="Left Align" onclick="goodsSearch($('#keyword').val())">搜索</button>
                       </form>
                   </div>
               </div>

               <div class="header-right cart">
                   <a href="./goods_cart.html">
                       <span class="glyphicon glyphicon-shopping-cart active" aria-hidden="true"><span class="card_num"></span></span>
                   </a>
               </div>
               <div class="clearfix"> </div>
           </div>
           <div class="clearfix"> </div>
       </div>
   </div>
<!--products-->
<div class="products">
	<div class="container">
		<h2> 搜索 ‘<span id="keywordlabel"></span>’的结果 </h2>
		<div class="col-md-12 product-model-sec"id="dgcontent">
		</div>
		<div>
		<div style='text-align:center;'>
               <a class='btn btn-info'>首页</a>
               <a class='btn btn-info'>上一页</a>
               <h3 style='display:inline;'>[/]</h3>
               <h3 style='display:inline;'>[]</h3>
               <a class='btn btn-info'>下一页</a>
               <a class='btn btn-info'>尾页</a>
               <input type='text' class='form-control' style='display:inline;width:60px;' value=''/><a class='btn btn-info' href='javascript:void(0);' onclick='location.href=""'>GO</a>
           </div>
		</div>
	</div>
</div>
<!--//products-->
<div class="footer">
       <div class="container">
           <div class="text-center">

           </div>
       </div>
</div>

</body>
<script type="text/javascript">
$(document).ready(function(){
  countMyCart();
  genGoodsTypesMenu();
  decorateMainMenu();
  var params = new URLSearchParams(window.location.search);
  var keyword = params.get("keyword");
  if (!isBlank(keyword)) {
    goodsSearch(keyword);
  }
});

function goodsSearch(keyword){
	$.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/goods_search",
		data: JSON.stringify({
		    keyword:keyword,
			page:1,
			rows:8,
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
			   for (let i=0;i<data.rows.length;i++){
				  appendGridRow(data.rows[i]);
				}
				appendClearFix();
				$("#keywordlabel").text(keyword);
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function appendGridRow(row){
  var rowStr = "<div class=\"product-grid\">\n"+
                "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
                "<div class=\"more-product\"><span> </span></div>\n"+
                "<div class=\"product-img b-link-stripe b-animate-go  thickbox\">\n"+
                "<img src=\"data:image/png;base64,"+row.cover+"\" class=\"img-responsive\" alt=\""+row.name+"\" width=\"240\" height=\"240\">\n"+
                "<div class=\"b-wrapper\">\n"+
                "<h4 class=\"b-animate b-from-left  b-delay03\">\n"+
                "<button href=\"./goods_detail.html?id="+row.id+"\">查看详情</button>\n"+
                "</h4>\n"+
                "</div>\n"+
                "</div>\n"+
                "</a>\n"+
                "<div class=\"product-info simpleCart_shelfItem\">\n"+
                "<div class=\"product-info-cust prt_name\">\n"+
                "<h4>"+row.name+"</h4>\n"+
                "<span class=\"item_price\">¥ "+row.price+"</span>\n"+
                "<input type=\"button\" class=\"item_add items\" value=\"加入购物车\" onclick=\"buy("+row.id+",1)\">\n"+
                "<div class=\"clearfix\"> </div>\n"+
                "</div>\n"+
                "</div>\n"+
                "</div>\n";
  $("#dgcontent").append(rowStr);
}

function appendClearFix(){
  var rowStr = "<div class=\"clearfix\"> </div>\n";
  $("#dgcontent").append(rowStr);
}
</script>
</html>
